class AccountController < ApplicationController
    
    layout "site"
    
    def login
        case @request.method
        when :post
            puts Account.authenticate(@params['account_login'], @params['account_password'])
            
            if account = Account.authenticate(@params['account_login'], @params['account_password'])
                puts "here"
            	@session['account'] = account.id
                flash['notice']  = "Login successful"
                redirect_back_or_default :controller => 'site', :action => 'site_show'
            else
                @login    = @params['account_login']
                @message  = "Login unsuccessful"
            end
        end
    end
    
    def signup
        case @request.method
        when :post
            @account = Account.new(@params['account'])
            User.make @account.login            
            if @account.save      
                account = Account.authenticate(@account.login, @params['account']['password'])
                @session['account'] = account.id
                flash['notice']  = "Signup successful"
                redirect_back_or_default :controller => "site", :action => "site_show"        
            end
        when :get
            @account = nil
        end      
    end  
    
    def logout
        @account = nil
        @session['account'] = nil
    end
	
    
end
